home *** CD-ROM | disk | FTP | other *** search
- (******************************************************************************
- * Ctm3d *
- ******************************************************************************)
- Unit Ctm3d;
-
- (*******************************************************************************
- * Homogeneous Coordinates *
- * ----------------------- *
- * *
- * Homogeneous coordinates allow transformations to be represented by *
- * matrices. A 3x3 matrix is used for 2D transformations, and a 4x4 matrix*
- * for 3D transformations. *
- * *
- * THIS MODULE IMPLEMENTS ONLY 3D TRANSFORMATIONS. *
- * *
- * in homogeneous coordination the point P(x,y,z) is represented as *
- * P(w*x, w*y, w*z, w) for any scale factor w!=0. *
- * in this module w == 1. *
- * *
- * Transformations: *
- * 1. translation *
- * [x, y, z] --> [x + Dx, y + Dy, z + Dz] *
- * *
- * ┌ ┐ *
- * │1 0 0 0│ *
- * T(Dx, Dy, Dz) = │0 1 0 0│ *
- * │0 0 1 0│ *
- * │Dx Dy Dz 1│ *
- * └ ┘ *
- * 2. scaling *
- * [x, y, z] --> [Sx * x, Sy * y, Sz * z] *
- * *
- * ┌ ┐ *
- * │Sx 0 0 0│ *
- * S(Sx, Sy) = │0 Sy 0 0│ *
- * │0 0 Sz 0│ *
- * │0 0 0 1│ *
- * └ ┘ *
- * *
- * 3. rotation *
- * *
- * a) Around the Z axis: *
- * *
- * [x, y, z] --> [x*cost - t*sint, x*sint + y*cost, z] *
- * ┌ ┐ *
- * │cost sint 0 0│ *
- * Rz(t) = │-sint cost 0 0│ *
- * │0 0 1 0│ *
- * │0 0 0 1│ *
- * └ ┘ *
- * *
- * b) Around the X axis: *
- * *
- * [x, y, z] --> [x, y*cost - z*sint, y*sint + z*cost] *
- * ┌ ┐ *
- * │1 0 0 0│ *
- * Rx(t) = │0 cost sint 0│ *
- * │0 -sint cost 0│ *
- * │0 0 0 1│ *
- * └ ┘ *
- * *
- * c) Around the Y axis: *
- * *
- * [x, y, z] --> [xcost + z*sint, y, z*cost - x*sint] *
- * ┌ ┐ *
- * │cost 0 -sint 0│ *
- * Ry(t) = │0 1 0 0│ *
- * │sint 0 cost 0│ *
- * │0 0 0 1│ *
- * └ ┘ *
- * *
- * transformation of the vector [x,y,z,1] by transformation matrix T is given *
- * by the formula: *
- * ┌ ┐ *
- * [x', y', z', 1] = [x,y,z,1]│ T │ *
- * └ ┘ *
- * Optimizations: *
- * The most general composition of R, S and T operations will produce a matrix*
- * of the form: *
- * ┌ ┐ *
- * │r11 r12 r13 0│ *
- * │r21 r22 r23 0│ *
- * │r31 r32 r33 0│ *
- * │tx ty tz 1│ *
- * └ ┘ *
- * The task of matrix multiplication can be simplified by *
- * x' = x*r11 + y*r21 + z*r31 + tx *
- * y' = x*r12 + y*r22 + z*r32 + ty *
- * z' = x*r13 + y*r23 + z*r33 + tz *
- * *
- * *
- * See also: *
- * "Fundamentals of Interactive Computer Graphics" J.D FOLEY A.VAN DAM *
- * Adison-Weslely ISBN 0-201-14468-9 pp 245-265 *
- *******************************************************************************)
-
- interface
-
- uses
- hdr3d
- ;
-
- type
- ctmPtr = ^ ctm;
- ctm = object
- r11, r12, r13 : real; { change to single if numeric processor is present }
- r21, r22, r23 : real;
- r31, r32, r33 : real;
- tx, ty, tz : real;
-
- constructor SetUnit; { set to the unit (I) matrix }
- constructor Copy(var src : ctm); { construct from another }
- procedure save(var dest : ctm);
-
- procedure translate(Dx, Dy, Dz : real); { used to move .. }
-
- procedure translateX(dx : real);
- procedure translateY(dy : real);
- procedure translateZ(dz : real); { translate in one axis only }
- {use these routines for single axis translations, they are faster!}
-
- procedure rotateX(t : real);
- procedure rotateY(t : real);
- procedure rotateZ(t : real);
-
- procedure scale(Sx, Sy, Sz : real);
-
- procedure scaleX(sx : real);
- procedure scaleY(sy : real);
- procedure scaleZ(sz : real);
- {use these routines for single axis scaling, they are faster!!!}
-
- procedure Left_translate(Dx, Dy, Dz : real);
-
- procedure Left_translateX(dx : real);
- procedure Left_translateY(dy : real);
- procedure Left_translateZ(dz : real);
- {use these Left_ routines for single axis translations, they are faster!}
-
- procedure Left_rotateX(t : real);
- procedure Left_rotateY(t : real);
- procedure Left_rotateZ(t : real);
-
- procedure Left_scale(Sx, Sy, Sz : real);
-
- procedure Left_scaleX(sx : real);
- procedure Left_scaleY(sy : real);
- procedure Left_scaleZ(sz : real);
- {use these routines for single axis scaling, they are faster!!!}
-
- procedure transform(var t: point3d; p : point3d);
- {
- Note that t (target) is var, but p is NOT.
- p cannot be a var parameter, because if the same point is
- transformed, data should be copied for correct results
- }
- procedure inv_transform(var p : point3d);
- { inv_transform changes the input point }
-
- procedure inverse; { M ^-1 .Bring the matrix to (-1) power}
- procedure multiply(var c : ctm); {multiply from right self * c}
- procedure Multiply_2(var a, b : ctm);
- end;
-
- implementation
- end.
-